@extends('layouts.console_header')

@section('title', 'Banner列表')

@section('resources')
    @parent
    <style>
        .banner_classify{padding: 10px 0 0 10px;margin: 5px 0;background-color: #fff;}
        .banner_classify a{font-size: 16px;margin-right: 60px;padding-bottom: 10px;cursor: pointer;}
        .banner_title select{width: 100px;height: 30px;line-height: 30px;text-align: center;border: 1px solid #000;margin: 9px 15px;}
        .banner_all li{background-color: #fff;}
        #example th{text-align: center;}
        .banner_show{color: #9955c6;border-bottom: 3px solid #9955c6;}
    </style>
@endsection

@section('content')
<!--  html内容  -->
<section class="user_list">
    <div style="border-bottom: 2px solid #9955c6;overflow: hidden;">
        <p class="fz_14 account_title fl" style="border: none;"><span style="color: #7f7f7f;"><a href="/console/index">首页</a>>用户版运营></span><span class="co_violet">Banner管理</span></p>
    </div>
    <ul class="banner_all">
        <li>
            <div class="banner_title" class="oh">
                <a style="color: #fff;" href="/console/user/banner/add?cityid={{$cityid}}&action=add"><p class="fr tc back_btn">+新增</p></a>
            </div>
            <table id="example" class="display" cellspacing="0" width="100%">
                <thead>
                    <tr>
                        <th>序号</th>
                        <th>Banner图片</th>
                        <th>Banner名称</th>
                        <th>发布类型</th>
                        <th>跳转类型</th>
                        <th>排序</th>
                        <th>上架时间</th>
                        <th>发布人</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th>序号</th>
                        <th>Banner图片</th>
                        <th>Banner名称</th>
                        <th>发布类型</th>
                        <th>跳转类型</th>
                        <th>排序</th>
                        <th>上架时间</th>
                        <th>发布人</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                </tfoot>
                <tbody>
                @foreach($bannerlists as $list)
                    <tr>
                        <td>{{$list['bannerid']}}</td>
                        <td>
                            <img style="width: 270px;height: 90px;" src="{{env('IMAGE_DOMAIN')}}{{$list['url']}}" alt="">
                        </td>
                        <td>{{$list['name']}}</td>
                    @if($list['isglobal'] == '1')
                        <td>全国</td>
                    @else
                        <td>当地</td>
                    @endif
                    @if($list['type'] == 'shop')
                        <td>商家详情</td>
                    @elseif($list['type'] == 'h5')
                        <td>H5页面</td>
                    @else
                        <td>空白页</td>
                    @endif
                        <td>{{$list['sort']}}</td>
                        <td>{{date('Y-m-d', strtotime($list['starttime']))}}</td>
                        <td>{{$list['realname']}}</td>
                    @if($list['status'] == '0')
                        <td>待发布</td>
                    @elseif($list['status'] == '1')
                        <td>已发布</td>
                    @elseif($list['status'] == '2')
                        <td>已下架</td>
                    @else
                        <td></td>
                    @endif
                        <td>
                        @if(($isglobal==1) || ($list['isglobal'] !=1))
                                <a class="revise co_violet" href="/console/user/banner/get?bannerid={{$list['bannerid']}}&cityid={{$cityid}}&action=edit">修改</a>
                            @if($list['status'] == '2')
                                <a class="forbidden co_violet" href="#" onclick="renew_banner('{{$list['bannerid']}}')">恢复</a>
                                <a class="revise co_red" href="#" onclick="delete_banner({{$list['bannerid']}})">删除</a>
                            @elseif($list['status'] == '1')
                                <a class="forbidden co_red" href="#" onclick="downshelf_banner({{$list['bannerid']}})">下架</a>
                            @endif
                        @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </li>
    </ul>
            
</section>
@endsection

@section('scriptResources')
    @parent
    <script>
    var cityid = '{{$cityid}}';
    //删除banner
    function delete_banner(bannerid) {
        var isconfirm = confirm("确定要删除？");
        if(isconfirm) {
            $.ajax({
                url : "/console/user/banner/delete",
                type : "post",
                data : {
                    bannerid:bannerid,
                    cityid:cityid
                    },
                dataType: "json",
                success:function (data){
                    if(data.status == 'success') {
                        window.location.href="/console/user/banner/list?cityid=" + cityid + "&now=" + Date.parse(new Date());
                    } else {
                        alert(data.message);
                    }
                }
            });
        }
    }
    //恢复上架
    function renew_banner(bannerid) {
        var isconfirm = confirm("确定要恢复？");
        if(isconfirm) {
            $.ajax({
                url : "/console/user/banner/status/update",
                type : "post",
                data : {
                    bannerid:bannerid,
                    cityid:cityid,
                    status:'1'
                    },
                dataType: "json",
                success:function (data){
                    if(data.status == 'success') {
                        alert(data.message);
                        window.location.href="/console/user/banner/list?cityid=" + cityid + "&now=" + Date.parse(new Date());
                    } else {
                        alert(data.message);
                    }
                }
            });
        }
    }
    //下架
    function downshelf_banner(bannerid) {
        var isconfirm = confirm("确定要下架？");
        if(isconfirm) {
            $.ajax({
                url : "/console/user/banner/status/update",
                type : "post",
                data : {
                    bannerid:bannerid,
                    cityid:cityid,
                    status:'2'
                    },
                dataType: "json",
                success:function (data){
                    if(data.status == 'success') {
                        alert(data.message);
                        window.location.href="/console/user/banner/list?cityid=" + cityid + "&now=" + Date.parse(new Date());
                    } else {
                        alert(data.message);
                    }
                }
            });
        }
    }
    </script>
@endsection